package com.zhangpingyang.springcloud.ribbonservice.controller;

import com.zhangpingyang.springcloud.ribbonservice.domain.CommonResult;
import com.zhangpingyang.springcloud.ribbonservice.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: Zhang Pingyang
 * @Date: 2019/11/27 16:02
 */
//@RequestMapping(value = "user")
@Controller
public class UserRibbonController {
    @Autowired
    private RestTemplate restTemplate;

    @Value("${service-url.user-service}")
    private String userServiceUrl;

    @RequestMapping("index")
    public String index() {
        return "index";
    }

    @GetMapping("user/{id}")
    @ResponseBody
    public CommonResult getUser(@PathVariable Long id) {
//        return restTemplate.getForObject(userServiceUrl + "/user/{1}", CommonResult.class, id);
        return restTemplate.getForObject(userServiceUrl + "/user/{1}", CommonResult.class, id);
    }
}
